<template>
  <view>
    <navBar ref='navRef' :navbarData.sync="navbarData"></navBar>
    <loading :showLoaded.sync="showLoaded"></loading>
    <wishDisplayList :navHeight='navHeight' :showIcon='showIcon' ref='wishDisplayListRef' @change='changeComponent'></wishDisplayList>
    <!-- <wishAddList ref='wishAddListRef' @change='changeComponent'></wishAddList> -->
  </view>
</template>

<script>
  import wishDisplayList from './components/wishDisplayList.vue'
  import wishAddList from './components/wishAddList.vue'
  import navBar from '@/components/common/navbar';
  import navbarVue from '../../components/common/navbar.vue';
  import Loading from '@/components/common/loading';
  import FavDialog from '@/components/common/favDialog.vue';

  export default {
    name: 'wishrWidget',
    components: {
      wishDisplayList,
      wishAddList,
      navBar,
      Loading,
      FavDialog
    },
    data() {
      return {
        navbarData: {
          showCapsule: 1,
          navbarTitle: '' //导航栏 中间的标题
        },
        showLoaded: false,
        wishAddList: [],
        showIcon: true,
        share: false,
        page: 1 ,//1心愿单页面 2添加心愿单页面
        navHeight:''
      }
    },
    mounted() {
      this.navHeight = this.$refs.navRef.getNavHeight()
      uni.hideShareMenu()
    },
    onShow() {
      if (this.page == 1) {
        this.init()
      } else {
        this.changeComponent('add')
      }
    },

    methods: {
      async init() {
        this.changeComponent('display')
      },

      getIconStatus() {
        this.$refs.wishAddListRef.getAddWishList('parent').then(res => {
          this.showIcon = res.length > 0 ? true : false
        }).catch(err => {
          this.showIcon = false
        })
      },
      handleLoading(val) {
        this.showLoaded = val
      },

      async changeComponent(val) {
        this.handleLoading(true)
        // if (val == 'add') {
        //   this.page = 2
        //   this.$refs.wishAddListRef.open()
        //   this.navbarData.navbarTitle = '添加心愿单'
        // } else if (val == 'display') {
          this.page = 1
          // await this.getIconStatus()
          this.$refs.wishDisplayListRef.open();
          this.navbarData.navbarTitle = '';
        // }
      },

      onShareAppMessage: function(res) {
        this.$commonSensors.sensorsPageShare()
        if (res.from == "button") {
          const {
            itemid,
            valueid,
            shareimageurl,
            pagetitle,
            majorurl
          } = res.target.dataset
          let sharePath = `/pages/item/item?id=${itemid}&valueId=${valueid}`
          let shareImage = shareimageurl || majorurl
					this.$sr.setContext({ share_title: pagetitle || 'THE MACALLAN EBOUTIQUE麦卡伦' });
          return this.$commonFunction.commonShare(res, pagetitle, sharePath, shareImage)
        }
      }
    },
  }
</script>

<style>

</style>
